package com.training2.bookstore.product.mapper;


import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.training2.bookstore.product.model.Product;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * User Mapper
 * </p>
 *
 * @author yangkai.shen
 * @date Created in 2018-11-08 10:54
 */
@Mapper
@Component
public interface ProductMapper {

    /**
     * 查询所有用户
     *
     * @return 用户列表
     */
    @Select("SELECT * FROM product")//List<Map<String, Object>> productCategoryId<->product_category_id
    List<Product> selectAllProducts();

    /**
     * 根据id查询用户
     *
     * @param id 主键id
     * @return 当前id的用户，不存在则是 {@code null}
     */
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product selectProducById(@Param("id") String id);

    /**
     * 保存用户
     *
     * @param user 用户
     * @return 成功 - {@code 1} 失败 - {@code 0}
     */
    int saveProduct(@Param("product") Product product);
   
    /**
     * 删除用户
     *
     * @param id 主键id
     * @return 成功 - {@code 1} 失败 - {@code 0}
     */
    int deleteById(@Param("id") String id);
    @Select("SELECT * FROM product WHERE name like #{n} and desc like e #{d}")
	Collection<Product> findByNameLikeOrDescLike(String n, String d);

}
